package Demo3;
import Demo2.Booklist;
import java.util.Scanner;

public class DelBook implements IFuntion{

    @Override
    public void work(Booklist booklist) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入删除的书籍名称:>");
        String bookName = scanner.nextLine();
        //遍历数组
        int sz = booklist.getCount();
        int i = 0 ;
        for (; i < sz; i++) {
            if(booklist.getBook(i).getName().equals(bookName)){
                break;//找到了
            }
        }
        //找不到
        if(sz == i) System.out.println("输入的书籍名称不存在！");
        //找到了
        else{
        for (; i < sz - 1; i++) {
            //使用set方法:将i+1下标的引用赋值给下标为i的引用
            booklist.setBook(booklist.getBook(),i);
        }
        //将数组count - 1
        booklist.setCount(sz - 1);
        //提示一下
        System.out.println("输入的书籍已经删除！");
        }
    }
}
